<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<%String path=request.getContextPath();String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<base href="<%=basePath%>">
	<title><s:text name="sys.app_title" /></title>
	<%@include file="../include/contentheader.jsp"%>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <link rel="stylesheet" type="text/css" href="css/main.css"/>
    <link rel="stylesheet" type="text/css" href="css/dtree.css"/>
	<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="js/dtree.js"></script>
	<script type="text/javascript" src="js/app.js"></script>
	<script type="text/javascript" src="dwr/engine.js"></script>
    <script type="text/javascript" src="dwr/util.js"></script>
    <script type="text/javascript" src="dwr/interface/department.js"></script>
 <script type="text/javascript">
//页面进行批量删除操作
   function deleteAll(){
      var allId = document.getElementsByName("checkbox");
      var array = new Array(allId.length);
      var j=0;
      for(var i=0;i<allId.length;i++){
         if(allId[i].checked==true){
              array[j] = allId[i].value;
              j++;
         }
      }
      //如果没有被选中，那么不进行任何操作
      if(j==0){
    	   alert('请选择要进行删除的记录.');
           return;
           }
      var newArray = new Array(j);
      for(var i=0;i<j;i++){
          newArray[i]=array[i];
      }
      if(confirm("确定要删除所选的记录吗？删除之后数据将不能恢复!")){
         document.getElementById("hiddenstaffid").value = newArray; 
         document.getElementById("hiddenform").submit();
      }
   }
//根据条件查询员工信息
   function queryStaff(){
	    location.href="queryStaff.action?FN=<s:property value='FN' />&condition="+encodeURIComponent($('#condition').val())+"&conditionValue="+encodeURIComponent($('#conditionValue').val());
   }
//将数据导出
   function ExportExcel(){ 
	   if(confirm("确定要导出所有记录吗?")){
          window.location.href="outputStaff.action";
	   } 
   }
//修改数据
   function update(){
	   var allId = document.getElementsByName("checkbox");
	      var array = new Array(allId.length);
	      var j=0;
	      for(var i=0;i<allId.length;i++){
	         if(allId[i].checked==true){
	              array[j] = allId[i].value;
	              j++;
	         }
	      }
	      //如果没有被选中，那么不进行任何操作
	      if(j==0){
	    	   alert('请选择要进行修改的记录.');
	           return;
	           }
	      var newArray = new Array(j);
	      for(var i=0;i<j;i++){
	          newArray[i]=array[i];
	      }
	      if(j > 1){
				alert('请选择某一条具体的记录再进行此操作.');
				return false;
			}
	         document.getElementById("updatestaffid").value = newArray; 
	         document.getElementById("updateform").submit();
	   }
//刷新页面
  function doRefresh(){
	    window.location.href="page/basic/searchStaff.action";
	  }
</script>
     
  </head>
  
  <body onload="buildTree()">
    <div class="mainContainer">
    <div class="headerTitle">基础信息管理&nbsp;>>&nbsp;员工管理</div>
        <div class="dtreeDiv" id="myTree">  
            <!-- 得到员工管理的树 -->	       
     <script type="text/javascript">
	       var myTree = document.getElementById("myTree");
	       d = new dTree('d');
	       var inner;
	function buildTree() {
		department.findDepartment(function(departmentList) {
			for ( var i = 0; i < departmentList.length; i++) {
			  if(i==0){
			      d.add(departmentList[i].depid,departmentList[i].depparentid,departmentList[i].depname,'searchStaff.action');
				  }
			 else{
				d.add(departmentList[i].depid,departmentList[i].depparentid,departmentList[i].depname,'queryStaffByDepartment.action?depid='+departmentList[i].depid);	
		         }
           }
			inner = d.toString();
			showBuildTree();
		});
	}
	function showBuildTree() {
		myTree.innerHTML = inner;
	}
     </script>

        </div>
        <div class="dataDivLeftHasTree">
        
<table class="gridTable" border="0" cellspacing="0" cellpadding="0">
	<tr class="operatorAction">
		<td>
			<!-- 功能性操作 -->
			
			<input type="button" style="margin-left:2px;" value="刷新" onclick="doRefresh()"/>
			<input type="button" style="margin-left:2px;" value="新增" onclick="javascript:window.location.href='findAllDepartment.action'"/>
			<input type="button" style="margin-left:2px;" value="修改" onclick="update()"/>
			<input type="button" style="margin-left:2px;" value="删除" onclick="deleteAll();"/>
			<input type="button" style="margin-left:2px;" value="导出" onclick="ExportExcel()"/>
			查询条件：根据&nbsp;&nbsp;<select style="width: 94px;"  id="condition">
		  					<option selected="selected" value="ygbh">员工编号</option>
		  					<option value="ygxm">员工姓名</option>
		  					<option value="ygzw">员工职位</option>
		  				</select><input style="margin-left:10px;" type="text" id="conditionValue"/>
		  	<input type="button" style="margin-left:1px;" value="查询" onclick="queryStaff()"/>
			
		</td>
	</tr>
	<tr>
		<td class="gridData">
		
	        <table class="dataTable" border="0" cellpadding="0" cellspacing="1">
	          <tr class="dataHeader">
	          	<!-- 数据表头 -->
	          	
	            <td width="6%"><input id="checkAll" type="checkbox" name="check" value="checkbox" /></td>
	            <td width="8%">员工编号</td>
	            <td width="10%">员工姓名</td>
	            <td width="10%">部门名称</td>
	            <td width="25%">身份证号</td>
	            <td width="10%">职位</td>
	            <td width="14%">电话号码</td>
	            <td width="14%">家庭地址</td>
	          </tr>
	          <!-- 数据 -->
	         <s:iterator var="sta" value="pagination.dataList"> 
	          <tr class="dataRow">
	            <td><input name="checkbox" type="checkbox" value="<s:property value='#sta[0].staid'/>" id="selectItem" /></td>
	            <td><s:property value="#sta[0].staid"/></td>
	            <td><s:property value="#sta[0].staname"/></td>
	            <td><s:property value="#sta[0].department.depname"/></td>
	            <td><s:property value="#sta[0].stacard"/></td>
	            <td><s:property value="#sta[0].staposition"/></td>
	            <td><s:property value="#sta[0].statel"/></td>
	            <td><s:property value="#sta[0].staaddress"/></td>
	          </tr>
	      	</s:iterator>
			</table>
	    
		</td>
	</tr>
	   <!-- 分页 -->
              <tr class="dataPager">
		       <td>
			     <s:property value="pageLink" escapeHtml="false" />
		       </td>
	          </tr>
	
</table>
        </div>
   </div>
<!-- 提交删除所有Id -->
   <form action="deleteStaff.action" method="post" id="hiddenform">
    	<input type="hidden" id="hiddenstaffid" name="staid"/>
   </form>
<!-- 提交修改根据Id的员工信息 -->
   <form action="findStaff.action" method="post" id="updateform">
    	<input type="hidden" id="updatestaffid" name="staid"/>
   </form>
<!-- 根据条件查询  -->
   <form method="post" id="hiddenform2">
     	<input type="hidden" id="hiddenCondition" name="condition"/>
     	<input type="hidden" id="hiddenConditionValue" name="conditionValue"/>
   </form>
</body>
</html>